﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace ServerExplorer.SharePointConnections.SharepointSiteInfo.Entities
{
    [Serializable]
    public class Page
    {

        private List<WebPartInfo> _webParts;

        [XmlElement("WebPart")]
        public List<WebPartInfo> WebParts
        {
            get { return _webParts; }
            set { _webParts = value; }
        }

        private string _relativeUrl;

        [XmlAttribute("Name")]
        public string PageName
        {
            get
            {
                string[] pageName = _relativeUrl.Split('/');
                return pageName.Last();
            }
            set { }
        }


        [XmlIgnore]
        public string RelativeUrl
        {
            get { return _relativeUrl; }
            set { _relativeUrl = value; }
        }

        public static implicit operator Page(string obj)
        {
            return new Page(obj);
        }

        private Page(string val)
            : this()
        {
            _relativeUrl = val;
        }

        public Page()
        {
            WebParts = new List<WebPartInfo>();
        }

        public override string ToString() { return RelativeUrl; }

    }
}
